package com.wy.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:王渝
 * @Date: 2022/11/30  15:53
 * @Version 1.0
 */
@Component
@Slf4j
public class PageInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("进入拦截器");
        Long adminId = (Long) request.getSession().getAttribute("adminId");
        if(adminId == null){
            response.sendRedirect("/page/backend/login.html");
            return false;
        }
        return true;
    }
}
